{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from numpy import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.46385805, 0.24297718, 0.43065248, 0.36549067],\n",
       "       [0.31500505, 0.27169966, 0.3490201 , 0.93812939],\n",
       "       [0.29122274, 0.87629611, 0.10849496, 0.50396987],\n",
       "       [0.09878035, 0.37637756, 0.75672587, 0.05273239]])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 产生随机数组\n",
    "random.rand(4, 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[0.44633022, 0.70638844, 0.30854657, 0.34925207],\n",
       "        [0.61570344, 0.09862037, 0.00317216, 0.07367276],\n",
       "        [0.39974178, 0.75321908, 0.49429094, 0.42168802],\n",
       "        [0.97697252, 0.93071453, 0.96320123, 0.00378914]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 将数组转化为矩阵\n",
    "randMat = mat(random.rand(4, 4))\n",
    "randMat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[-0.45808519,  1.74466218,  0.07366136,  0.10319351],\n",
       "        [ 6.11858433, -2.11255596, -4.70261004,  0.46022645],\n",
       "        [-5.43134274,  0.26457947,  4.44769767,  0.49473175],\n",
       "        [-4.12830124,  1.80945113,  5.48792787, -1.49979014]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 矩阵求逆运算\n",
    "invRandMat = randMat.I\n",
    "invRandMat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[ 1.00000000e+00,  0.00000000e+00, -4.44089210e-16,\n",
       "          1.11022302e-16],\n",
       "        [ 1.66533454e-16,  1.00000000e+00,  0.00000000e+00,\n",
       "          9.71445147e-17],\n",
       "        [-4.44089210e-16,  0.00000000e+00,  1.00000000e+00,\n",
       "          0.00000000e+00],\n",
       "        [ 2.28983499e-16, -9.02056208e-17,  2.56739074e-16,\n",
       "          1.00000000e+00]])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 含有误差的单位矩阵\n",
    "myEye = randMat * invRandMat\n",
    "myEye"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 0., 0., 0.],\n",
       "       [0., 1., 0., 0.],\n",
       "       [0., 0., 1., 0.],\n",
       "       [0., 0., 0., 1.]])"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 构建单位矩阵\n",
    "eye(4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
